package common.properties.validation {
import common.properties.HasProperties;
import common.properties.PropertyAccessor;

import mx.validators.Validator;

/**
 * Валидатор для PropertiesPanel. Для работы необходимо переопределить doValidation
 */
public class PropertyValidator extends Validator {

    private var _accessor:PropertyAccessor;

    public function set accessor(value:PropertyAccessor):void {
        _accessor = value;
    }

    override protected function getValueFromSource():Object {
        var message:String;

        if (_accessor && source && source is HasProperties) {
            return _accessor.getValue(HasProperties(source));
        }

        else if (!source && _accessor) {
            message = resourceManager.getString(
                    "validators", "SAttributeMissing");
            throw new Error(message);
        }

        else if (source && !_accessor) {
            message = resourceManager.getString(
                    "validators", "PAttributeMissing");
            throw new Error(message);
        }

        return null;
    }

    public function PropertyValidator() {
    }
}
}